package com.zhijian.warehouse.manage.controller.app;

import com.zhijian.response.annotation.Response;
import com.zhijian.util.page.Page;
import com.zhijian.warehouse.manage.entity.dto.UserDto;
import com.zhijian.warehouse.manage.entity.vo.request.UserSaveOrUpdateVo;
import com.zhijian.warehouse.manage.entity.vo.request.UserSearchVo;
import com.zhijian.warehouse.manage.entity.vo.response.UserVo;
import com.zhijian.warehouse.manage.holder.CurrentMpUserHolder;
import com.zhijian.warehouse.manage.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 人员 控制层
 *
 * @author auto
 * @version 1.0
 * @date 2024-10-09 16:34:28
 */
@Slf4j
@Controller
@Api(tags = "app人员列表")
@RequestMapping("/app")
public class AppUserController {
    
    @Autowired
    private UserService service;
    
    
    /**
     * 分页查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/user/page")
    @ApiOperation("分页查询")
    public Page<UserVo> selectByCondition(@RequestBody(required = false) UserSearchVo param) {
        if (param == null)
            param = UserSearchVo.builder().build();
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return service.selectPage(param);
    }
    
    /**
     * 列表查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/user/list")
    @ApiOperation("列表查询")
    public List<UserVo> selectList(@RequestBody(required = false) UserSearchVo param) {
        if (param == null)
            param = UserSearchVo.builder().build();
        log.info("{} - {}| selectList info", this.getClass().getSimpleName(), param);
        return service.selectList(param);
    }
    
    /**
     * 列表查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/user/list/msg")
    @ApiOperation("列表查询")
    public List<UserVo> selectListMsg(@RequestBody(required = false) UserSearchVo param) {
        if (param == null)
            param = UserSearchVo.builder().build();
        log.info("{} - {}| selectListMsg info", this.getClass().getSimpleName(), param);
        return service.selectListMsg(param);
    }
    
    /**
     * 校验密码正确或者错误
     *
     * @param param
     * @return
     */
    @Response
    @PutMapping("/user/audit/pass/check")
    @ApiOperation("校验密码正确或者错误")
    public boolean checkAuditPass(@RequestBody UserSaveOrUpdateVo param) {
        log.info("{} - {}| update info, {}", this.getClass().getSimpleName(), param);
        UserDto user = CurrentMpUserHolder.getUser();
        param.setId(user.getId());
        return service.checkAuditPass(param);
    }
    
    /**
     * 校验密码是否失效
     *
     * @param param
     * @return
     */
    @Response
    @GetMapping("/user/audit/pass/check/time")
    @ApiOperation("校验密码是否失效")
    public boolean checkAuditPassTime() {
        log.info("{} - {}| update info, {}", this.getClass().getSimpleName());
        UserDto user = CurrentMpUserHolder.getUser();
        UserSaveOrUpdateVo param = UserSaveOrUpdateVo.builder().build();
        param.setId(user.getId());
        return service.checkAuditPassTime(param);
    }
    
}
